@echo off
goto endTitle
============================================================================

    Run All Surveyor Tests

    Provides a convienent way to execute all Surveyor automated tests.
    This should be run before any commits.

============================================================================
 Copyright 2008-2011, Matt Peloquin and Construx. This file is part of Code
 Surveyor, covered under GNU GPL v3 and is distributed WITHOUT ANY WARRANTY
============================================================================
:endTitle

echo.
echo.
echo               Starting Surveyor Tests
echo.
echo  MAKE SURE TestFiles.zip AND TestOracle.zip are UNZIPPED
echo.

del output\* /Q

echo.
echo +++++++++++++++++++++++++++++++++++++++++++
echo  Static Analysis
echo +++++++++++++++++++++++++++++++++++++++++++
echo.

call Pycheck.bat > output\PyChecker_Output.txt

REM Create file that excludes known warnings
fc static\PyCheckerKnownWarnings.txt output\PyChecker_Output.txt | FIND "****" > output\PyChecker_NewWarnings.txt

REM Crazy DOS way to get size of file
for %%A in (output\PyChecker_NewWarnings.txt) do SET PYCHECKER_WARNINGS_SIZE=%%~zA

if %PYCHECKER_WARNINGS_SIZE% EQU 0 goto :END_PYCHECKER

echo.
echo   PyChecker has new Warnings! 
echo   Compare additions below against content of: static\PyCheckerKnownWarnings.txt 
type output\PyChecker_Output.txt
goto FAIL
:END_PYCHECKER

REM  Allow for Python version to be passed on command line
if !%1==! (
    SET PYTHON=
) else (
    SET PYTHON=%1
)
echo.
echo  Python running from: %PYTHON%

echo.
echo +++++++++++++++++++++++++++++++++++++++++++
echo  Python Script Tests
echo +++++++++++++++++++++++++++++++++++++++++++
echo.

call %PYTHON% scripts\run_scripts.py unit
if ERRORLEVEL 1 goto FAIL

call %PYTHON% scripts\run_scripts.py module
if ERRORLEVEL 1 goto FAIL

call %PYTHON% scripts\run_scripts.py system
if ERRORLEVEL 1 goto FAIL

echo.
echo +++++++++++++++++++++++++++++++++++++++++++
echo  Command Line Tests
echo +++++++++++++++++++++++++++++++++++++++++++
echo.

call CmdLineTests.bat %PYTHON% > output\CmdLineTests.txt

IF DEFINED SURVEYOR_CMD_LINE_TEST_SUCCESS goto ORACLE ELSE goto FAIL

:ORACLE
echo.
echo +++++++++++++++++++++++++++++++++++++++++++
echo  Checking Oracle
echo +++++++++++++++++++++++++++++++++++++++++++
echo.

call checkOracle.bat 

IF DEFINED ORACLE_COMPARE_GOOD goto SUCCESS ELSE goto FAIL


:FAIL
(SET SURVEYOR_RUN_TEST_SUCCESS=)
echo.
echo      =============================
echo             TESTING FAILED
echo      =============================
goto END

:SUCCESS
(SET SURVEYOR_RUN_TEST_SUCCESS=1)
echo.
echo      =============================
echo          All Tests Succeeded!
echo      =============================

:END
echo.
echo.
